package com.csdj.t309.geamtest.service;

import com.csdj.t309.geamtest.common.CacheConstant;
import com.csdj.t309.geamtest.entity.Blindbox;
import com.csdj.t309.geamtest.mapper.BlindboxMapper;
import com.csdj.t309.geamtest.service.IBlindboxService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 田港
 * @since 2022-01-20
 */
@Service
public class BlindboxService extends ServiceImpl<BlindboxMapper, Blindbox> implements IBlindboxService {
    @Resource
    private BlindboxMapper blindboxMapper;
    @Resource
    private IUserService userService;

    @Override
    public List<Integer> selbox(Integer jsId,Integer id) {
        Integer num = id;
        HashMap<String,Object> map = new HashMap<>();
        map.put("bb_js_id",jsId);
        map.put("bb_user_id",num);
        List<Blindbox> list = blindboxMapper.selectByMap(map);
        List<Integer> zong = new ArrayList<Integer>();
        for(Integer i = 0 ; i < 9 ; i++){
            zong.add(i);
        }
        List<Integer> a = new ArrayList<Integer>();
        for(Blindbox i : list){
            a.add(i.getBbBianHao());
        }
        zong.removeAll(a);
        if(zong.size()>0){
            return zong;
        }else {
            Blindbox blindbox = new Blindbox();
            blindbox.setBbJsId(jsId);
            blindbox.setBbUserId(num);
            blindboxMapper.deleteById(blindbox);
            return null;
        }
    }
}
